// 这是第一步 封装Socket并且配一个buffer缓冲区
#pragma once
#include <sys/epoll.h>
#include <cstdint>
#include <memory>
#include <functional>
#include "InetAddr.hpp"
#include "Socket.hpp"
// 项目头文件
#include "reactor.hpp"
// Connection 表示收到的一天链接
using callback_t = std::function<std::string(std::string &inbuffer)>;
class Reactor;
class Connection
{
public:
    // 这里是一个抽象类，抽象类不能实例化出对象
    Connection()
    {
    }
    virtual void Recver() = 0; // 处理读
    virtual void Sender() = 0; // 处理写
    virtual void Excepter() = 0;
    int Sockfd()
    {
        return _sockfd;
    }
    void SetEvents(uint32_t events)
    {
        _events = events;
    }
    uint32_t Events()
    {
        return _events;
    }
    void SetSocketfd(int fd)
    {
        _sockfd = fd;
    }
    void SetAddr(InetAddr client)
    {
        _peer = client;
    }
    Reactor *Owner()
    {
        return owner;
    }
    void SetOwner(Reactor *r)
    {
        owner = r;
    }
    void SetCb(callback_t cb)
    {
        _cb = cb;
    }

    ~Connection()
    {
    }

protected:
    int _sockfd;

    std::string _inbuffer; // 这里其实更加推荐用 vector<char> 因为我们可能读取的也可能是二进制的信息
    std::string _outbuffer;

    InetAddr _peer;

    uint32_t _events;

    struct Reactor *owner;

    callback_t _cb;
};
